package com.kma.summer2012.client;

import com.googlecode.gwt.crypto.bouncycastle.DataLengthException;
import com.googlecode.gwt.crypto.bouncycastle.InvalidCipherTextException;
import com.googlecode.gwt.crypto.client.TripleDesCipher;
import com.googlecode.gwt.crypto.client.TripleDesKeyGenerator;

public class Crypto {

    final static String GWT_DES_KEY = "c4bcce7fc4010d2520b9efe67cecc480cb0201ec2cc24f3e";

    public static String encrypt(String password) {
        String enc = null;
        TripleDesCipher cipher = new TripleDesCipher();
        TripleDesKeyGenerator generator = new TripleDesKeyGenerator();
        cipher.setKey(generator.decodeKey(GWT_DES_KEY));
        try {
            enc = cipher.encrypt(password);
        } catch (DataLengthException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (InvalidCipherTextException e) {
            e.printStackTrace();
        }
        return enc;
        // return password;
    }

    public static String decrypt(String hash) {
        // return hash;

        String dec = null;
        TripleDesCipher cipher = new TripleDesCipher();
        TripleDesKeyGenerator generator = new TripleDesKeyGenerator();
        cipher.setKey(generator.decodeKey(GWT_DES_KEY));
        try {
            dec = cipher.decrypt(hash);
        } catch (DataLengthException e) {
            e.printStackTrace();
        } catch (IllegalStateException e) {
            e.printStackTrace();
        } catch (InvalidCipherTextException e) {
            e.printStackTrace();
        }
        return dec;

    }
}